package com.x.crm.dao;

import com.x.crm.model.FollowOrder;
import com.x.framework.dao.BaseDao;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class FollowOrderDao extends BaseDao{


	private final static String baseSelectFollowOrderListSql = "SELECT * FROM  CRM_FOLLOW_ORDER  I " +
			"WHERE 1=1 ";

	public List<FollowOrder> selectFollowOrderList(FollowOrder followOrder) throws Exception {
		StringBuilder sb = new StringBuilder(baseSelectFollowOrderListSql);
		List<Object> params = new ArrayList<Object>();
		searchBasicCondition(followOrder, sb, params);
		sb.append(" ORDER BY I.FOLLOW_ORDER_CREATE_TIME DESC");
		return this.queryForList(sb.toString(), FollowOrder.class, params, followOrder);
	}


	private void searchBasicCondition(FollowOrder followOrder, StringBuilder sb, List<Object> params) {
		if (this.isString(followOrder.getIntentionId())) {
			sb.append("AND I.INTENTION_ID = ? ");
			params.add(followOrder.getIntentionId());
		}
		if (this.isString(followOrder.getFollowOrderId())) {
			sb.append("AND I.FOLLOW_ORDER_ID = ? ");
			params.add(followOrder.getFollowOrderId());
		}
		if (followOrder.getOrderCarState() != null) {
			sb.append("AND I.ORDER_CAR_STATE = ? ");
			params.add(followOrder.getOrderCarState());
		}
	}


}
